function getAssignment(a)
{
    post("http://123.207.251.172/data/request/get-assignment",{
        refer: a
    },function (data)
    {

        if (data.code == 200) {
            if (a === 0) {
                var trs1 = $("#UFA_tr").clone(true);
                $("#UFA_tr").remove()
                $.each(data.t, function (a, b) {
                    var trs = trs1.clone(true);

                    trs.attr('id', 'UFA_tr' + a)
                    trs.children().eq(0).text(b.aid)
                    trs.children().eq(1).text(b.courseName)
                    trs.children().eq(2).text(b.assignmentName)
                    trs.children().eq(3).text(b.detail)
                    trs.children().eq(4).text(b.isFinish)
                    trs.children().eq(5).children().eq(1).children().attr('href', 'javascript:to_upload(' + a + ')')
                    console.log(trs.children().eq(4).children().eq(1).children().attr('href'))
                    $("#UFA_tb").append(trs);
                })
            } else if (a === 1) {

            } else if (a === 10) {

            }
        } else {
            alert(data.reason)
        }

    })
}
function get_Course_Condition() {
    post("http://123.207.251.172/data/request/get-course-condition", {
        refer: $("#finish-button").text(),
        cno:$("#cno").text(),
        courseName:$("#course-button").text()
    }, function (data) {
        if (data.code == 200) {

            $("#course-show").text(data.t[0].courseName)
            $("#UFA_tr").show();
            $.each(data.t, function (a, b) {
                var trs = $("#UFA_tr").clone(true);
                trs.attr('id', 'UFA_tr' + a)
                trs.children().eq(0).text(b.sid)
                trs.children().eq(1).text(b.studentName)
                trs.children().eq(2).text(b.isFinish)
                trs.children().eq(3).children().eq(1).children().attr('href', 'javascript:to_upload(' + a + ')')
                $("#UFA_tb").append(trs);
            })
            $("#UFA_tr").hide();
        } else {
            alert(data.reason)
        }



    })
}
function getCourse()
{
    post("http://123.207.251.172/data/request/getCourse", {

    }, function (data) {
        if (data.code == 200&&data.t!=null) {

            $("#course-button").text(data.t[0].name)
            var trs1 = $("#course-select").clone(true);
            $("#course-select").remove()
            $.each(data.t, function (a, b) {
                var trs = trs1.clone(true);
                trs.attr('id', 'course-select' + a)
                trs.text(b.name)
                trs.attr('href', 'javascript:changeCourse(' + a + ')')
                $("#course-list").append(trs);
            })

            get_Course_Condition();


        }
        else
        {
            alert(data.reason)
        }


    })
}
function changeCourse(a)
{
    $("#course-button").text($("#course-select"+ a).text());
    $("#UFA_tr").show();
    var trs=$("#UFA_tr").clone(true);
    $("#UFA_tb").empty();
    $("#UFA_tb").append(trs);
    get_Course_Condition();
    $("#UFA_tr").hide();
}
function changeFinish(a)
{
    $("#finish-button").text(a);
    $("#UFA_tr").show();
    var trs=$("#UFA_tr").clone(true);
    $("#UFA_tb").empty();
    $("#UFA_tb").append(trs);
    get_Course_Condition();
    $("#UFA_tr").hide();
}
function to_upload(e)
{
    aid=$("#UFA_tr"+e).children().eq(0).text();
    courseName=$("#UFA_tr"+e).children().eq(1).text();
    assignmentName=$("#UFA_tr"+e).children().eq(2).text();
    detail=$("#UFA_tr"+e).children().eq(3).text();
    jump_to_load();

    function jump_to_load()
    {
      url="upload2.html?aid="+aid+"&courseName="+courseName+"&assignmentName="+assignmentName+"&detail="+detail;
      window.location.href=url;
    }
}


function get(url, success,error){
    $.ajax({
        type: "get",
        url: url,
        async: true,
        dataType: 'json',
        beforeSend:function (xhr)
        {
            xhr.setRequestHeader("token",localStorage.getItem('token'))
        },
        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}

function post(url, data, success,error){
    $.ajax({
        type: "post",
        url: url,
        async: true,
        data: data,
        dataType: 'json',
        beforeSend:function (xhr)
        {
            xhr.setRequestHeader("token",localStorage.getItem('token'))
        },
        xhrFields: {
            withCredentials: true
        },
        success: success,
        error: error
    });
}